//
//  HLiveFinishView.m
//  linktuIOS
//
//  Created by hejunsong on 17/1/21.
//  Copyright © 2017年 tianxie. All rights reserved.
//

#import "HLiveFinishView.h"

#import "Masonry.h"
@interface HLiveFinishView()<HLiveShareViewDelegate>
@property(nonatomic,strong) UILabel *titleLable;
@property(nonatomic,strong) HLiveShareView *shareView;
@property(nonatomic,strong)  UIButton *fllowingButton;
@property(nonatomic,strong) UIButton *backButton;

@property(nonatomic,strong) UIImageView *imageView;
@property(nonatomic,strong) UILabel *nameLable;

@end

@implementation HLiveFinishView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = UIColorFromRGB(0x666666);
        [self makeUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8]];
        [self makeUI];
    }
    return self;
}
+(instancetype)hlivefinishView
{
    HLiveFinishView *view = [[HLiveFinishView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    return view;
}

-(void)makeUI
{
    _nameLable = [UILabel new];
    _imageView = [UIImageView new];
    _imageView.layer.masksToBounds = YES;
    _imageView.layer.cornerRadius = 50;
    
    _nameLable.font = [UIFont boldSystemFontOfSize:14];
    _nameLable.textColor = [UIColor whiteColor];
    
    _titleLable = [UILabel new];
    _shareView = [[HLiveShareView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    _shareView.delegate = self;
    _fllowingButton = [UIButton new];
    _backButton = [UIButton new];
    
    _titleLable.text =  NSLTLocalizedString(@"直播结束", nil);
    _titleLable.textAlignment = NSTextAlignmentCenter;
    _titleLable.font = [UIFont systemFontOfSize:25];
    _titleLable.backgroundColor = [UIColor clearColor];
    _titleLable.textColor =  mainTintColor;
    
    [_fllowingButton setTitle:NSLTLocalizedString(@"关注主播", nil) forState:UIControlStateNormal];
    [_backButton setTitle:NSLTLocalizedString(@"返回首页", nil) forState:UIControlStateNormal];
    
    _fllowingButton.titleLabel.font = [UIFont systemFontOfSize:15];
    _fllowingButton.backgroundColor = mainButtonColor;
    _fllowingButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    _backButton.titleLabel.font = [UIFont systemFontOfSize:15];
    _backButton.backgroundColor = [UIColor clearColor];
    _backButton.layer.borderWidth = 1;
    _backButton.layer.borderColor = mainButtonColor.CGColor;
    _backButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    [_backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [_fllowingButton addTarget:self action:@selector(backSaveClick) forControlEvents:UIControlEventTouchUpInside];
    
    _shareView.backgroundColor = [UIColor clearColor];
    _backButton.layer.cornerRadius = 20;
    _backButton.layer.masksToBounds = YES;
    
    
    _fllowingButton.layer.cornerRadius = 20;
    _fllowingButton.layer.masksToBounds = YES;
    
    
    [self addSubview:_imageView];
    [self addSubview:_nameLable];
    
    [self addSubview:_titleLable];
    [self addSubview:_shareView];
    [self addSubview:_fllowingButton];
    [self addSubview:_backButton];
    
    
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top).offset(80);
        make.width.mas_equalTo(@100);
        make.height.mas_equalTo(@100);
        make.centerX.mas_equalTo(self.mas_centerX).offset(0);
    }];
    
    [_nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.imageView.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self.mas_centerX).offset(0);
    }];
    
    
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.nameLable.mas_bottom).offset(10);
        make.left.mas_equalTo(self.mas_left).offset(20);
        make.right.mas_equalTo(self.mas_right).offset(-20);
    }];
    
    [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(@40);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-80);
        make.width.mas_equalTo(@225);
        make.centerX.mas_equalTo(self.mas_centerX).offset(0);
    }];
    
    [_fllowingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(@40);
        make.bottom.mas_equalTo(_backButton.mas_top).offset(-10);
        make.width.mas_equalTo(@225);
        make.centerX.mas_equalTo(self.mas_centerX).offset(0);
    }];
    
    [_shareView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(@40);
        make.bottom.mas_equalTo(_fllowingButton.mas_top).offset(-10);
        make.width.mas_equalTo(@225);
        make.centerX.mas_equalTo(self.mas_centerX).offset(0);
    }];
}
-(void)setLiveModel:(MTLiveModel *)liveModel
{
    _liveModel = liveModel;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:liveModel.anchor.avatar] placeholderImage:defaultImgae];
    self.nameLable.text = liveModel.anchor.name;
    if(liveModel.anchor.follow)
    {
        self.fllowingButton.hidden = YES;
    }else
    {
        self.fllowingButton.hidden = NO;
    }
}


-(void)backClick
{
    if(self.delegate && [self.delegate respondsToSelector:@selector(hlivefinishView:withButtonType:)])
    {
        [self.delegate hlivefinishView:self withButtonType:finishedLiveClickTypeBack];
    }
}
-(void)backSaveClick
{
    if(self.delegate && [self.delegate respondsToSelector:@selector(hlivefinishView:withButtonType:)])
    {
        [self.delegate hlivefinishView:self withButtonType:finishedLiveClickTypeBackAndSave];
    }
    
}
-(void)hliveShareView:(HLiveShareView *)shareView withType:(Sharetype)type
{
    if(self.delegate && [self.delegate respondsToSelector:@selector(hlivefinishView:withShareType:)])
    {
        [self.delegate hlivefinishView:self withShareType:type];
    }
}

@end
